package com.hiyee.api.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
 * RabbitMq 配置类
 *
 */
@Configuration
public class RabbitMqConfig {

    // 定义交换机的名字
    public final static String EXCHANGE_NAME = "hiyee_news_exchange";
    // 定义队列的名字
    public final static String QUEUE_NAME = "hiyee_news_queue";

    // 创建交换机
    @Bean(EXCHANGE_NAME)
    public Exchange exchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    // 创建队列
    public Queue queue() {
        return new Queue(QUEUE_NAME);
    }

    // 队列绑定交换机
    public Binding binding(@Qualifier(EXCHANGE_NAME) Exchange exchange, @Qualifier(QUEUE_NAME) Queue queue) {
        return BindingBuilder
                .bind(queue)
                .to(exchange)
                .with("article.*") // * 代表一个占位符，可以是 article.*.*
                .noargs();
    }
}
